package com.apes.autoparts.matchingRule;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.apes.framework.query.ApesDao;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component
public class VoluntaryOffersDao extends ApesDao {


    /**
     *匹配规则匹配商品
     * @return
     */
    public JSONArray findByPPGZ(JSONObject param){
        // 从数据中心服务中,提供电子目录查询接口
        String sSQL_JCYLX = "SELECT ZDMC, PPGZ, SJLXID, PPZ,ZWMC FROM MAS_CXPJPPGZ@erp_Dblink  WHERE PJMCID=:PJMCID AND PZCXID=:PZCXID ";
        return toJSONArray(find(sSQL_JCYLX,param));
    }


    /**
     * 配置车型匹配规则(PZCXID)
     * @param param
     * @return
     */
    public JSONArray findByPZCXID(JSONObject param){
        String sSQL_JCYLX = "SELECT A.PZCXID,A.QCCPMC,A.QCPPMC FROM MAS_QCCXPZ@erp_Dblink A WHERE A.PZCXID=:PZCXID" ;
        return toJSONArray(find(sSQL_JCYLX,param));
    }

    /**
     * 配件名称ID替代件关系查询
     * @param param
     * @return
     */
    public JSONArray findMountingsIDReplace(JSONObject param){
        String sSQL_JCYLX = "SELECT TDPJMCID FROM MAS_PJTDKZB@erp_Dblink WHERE  PJMCID=:PJMCID" ;
        return toJSONArray(find(sSQL_JCYLX,param));
    }

    /**
     *电子目录匹配规则(PZCXID PJMCID)
     * @param param
     * @return(OE号，配件名称)
     */
    public List<Map> findByCXDZML(JSONObject param){
        String  sSql = "SELECT C.PJMC,C.OEID FROM ( "+
                "  SELECT A.OEID,A.PJMC FROM MAS_CXPJDZML_1@erp_Dblink A WHERE A.YXBJ = 1 AND A.PJMCID = :PJMCID AND A.PZCXID = :PZCXID "+
                "  UNION ALL "+
                "  SELECT B.OEID,B.PJMC FROM MAS_CXPJDZML_3@erp_Dblink B WHERE B.PJMCID = :PJMCID AND B.PZCXID = :PZCXID "+
                ") C GROUP BY C.OEID,C.PJMC";
        return find(sSql,param);
    }









}
